package com.burry.action;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;
import applelew.util.Debug;

import com.burry.bo.JSONResult;
import com.burry.services.CatalogService;
import com.burry.services.GoodService;

public class GoodAction extends BaseAction {
	
	private String selectStr;
	private String inputGoodId;
	private String inputFea;
	private String cname;
	private String goodIntro;
	private String goodDes;
	private String goodDesign;
	private String goodSize;
	private String cPrice;
	private String oPrice;
	private String mPrice;
	private String sPrice;
	private String likeId;
	private String proId;
	private String cataCode;
	private String goodTag;
	private String goodSell;
	
	public String getGoodTag() {
		return goodTag;
	}

	public void setGoodTag(String goodTag) {
		this.goodTag = goodTag;
	}

	public String getGoodSell() {
		return goodSell;
	}

	public void setGoodSell(String goodSell) {
		this.goodSell = goodSell;
	}

	public String getCataCode() {
		return cataCode;
	}

	public void setCataCode(String cataCode) {
		this.cataCode = cataCode;
	}

	public String getLikeId() {
		return likeId;
	}

	public void setLikeId(String likeId) {
		this.likeId = likeId;
	}

	public String getProId() {
		return proId;
	}

	public void setProId(String proId) {
		this.proId = proId;
	}

	public String getCPrice() {
		return cPrice;
	}

	public void setCPrice(String price) {
		cPrice = price;
	}

	public String getOPrice() {
		return oPrice;
	}

	public void setOPrice(String price) {
		oPrice = price;
	}

	public String getMPrice() {
		return mPrice;
	}

	public void setMPrice(String price) {
		mPrice = price;
	}

	public String getSPrice() {
		return sPrice;
	}

	public void setSPrice(String price) {
		sPrice = price;
	}


	private InputStream inputStream;
	
	
	public InputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	public String getInputGoodId() {
		return inputGoodId;
	}

	public void setInputGoodId(String inputGoodId) {
		this.inputGoodId = inputGoodId;
	}

	public String getInputFea() {
		return inputFea;
	}

	public void setInputFea(String inputFea) {
		this.inputFea = inputFea;
	}

	public String getCname() {
		return cname;
	}

	public void setCname(String cname) {
		this.cname = cname;
	}

	public String getGoodIntro() {
		return goodIntro;
	}

	public void setGoodIntro(String goodIntro) {
		this.goodIntro = goodIntro;
	}

	public String getGoodDes() {
		return goodDes;
	}

	public void setGoodDes(String goodDes) {
		this.goodDes = goodDes;
	}

	public String getGoodDesign() {
		return goodDesign;
	}

	public void setGoodDesign(String goodDesign) {
		this.goodDesign = goodDesign;
	}

	public String getGoodSize() {
		return goodSize;
	}

	public void setGoodSize(String goodSize) {
		this.goodSize = goodSize;
	}

	public String getSelectStr() {
		return selectStr;
	}

	public void setSelectStr(String selectStr) {
		this.selectStr = selectStr;
	}

	public String goodCataInit(){
		GoodService gs = new GoodService();
		selectStr = gs.goodCataInit(CatalogService.allFaCataInfo);
		return SUCCESS;
	}
	
	public String listGoodInit(){
		GoodService gs = new GoodService();
		List goodList = gs.getAllGood();
		
		JSONResult json = new JSONResult(goodList);
		JSONObject jsonRet = JSONObject.fromObject(json);  
		String allSize = jsonRet.toString();

		try {
			setInputStream(new ByteArrayInputStream(allSize.getBytes("utf-8")));
		} catch (UnsupportedEncodingException e) {
			Debug.logError(e.getMessage());
		}
		return SUCCESS;
	}
	
	public String listSubColorInit(){
		GoodService gs = new GoodService();
		HttpServletRequest request = super.getRequest();
		String goodId = request.getParameter("goodId");
		List goodList = gs.getAllSubColor(goodId);
		
		JSONResult json = new JSONResult(goodList);
		JSONObject jsonRet = JSONObject.fromObject(json);  
		String allSize = jsonRet.toString();

		try {
			setInputStream(new ByteArrayInputStream(allSize.getBytes("utf-8")));
		} catch (UnsupportedEncodingException e) {
			Debug.logError(e.getMessage());
		}
		return SUCCESS;
	}
	
	public String listSuitColorInit(){
		GoodService gs = new GoodService();
		HttpServletRequest request = super.getRequest();
		String goodId = request.getParameter("goodId");
		String colorId = request.getParameter("colorId");
		List goodList = gs.getAllSuitColor(goodId, colorId);
		
		JSONResult json = new JSONResult(goodList);
		JSONObject jsonRet = JSONObject.fromObject(json);  
		String allSize = jsonRet.toString();

		try {
			setInputStream(new ByteArrayInputStream(allSize.getBytes("utf-8")));
		} catch (UnsupportedEncodingException e) {
			Debug.logError(e.getMessage());
		}
		return SUCCESS;
	}
	
	
	public String addGood(){
		GoodService gs = new GoodService();
		gs.addAGood(inputGoodId, inputFea, cname, goodIntro, goodDes, goodDesign, goodSize,cPrice,oPrice,mPrice,sPrice,goodTag,goodSell);
		gs.addGoodCataInfo(inputGoodId, cataCode);
		return SUCCESS;
	}
	
	public String delGood(){
		GoodService gs = new GoodService();
		gs.delGood(inputGoodId);
		return SUCCESS;
	}
	
	public String addSomeLike(){
		GoodService gs = new GoodService();
		gs.addSomeLike(inputGoodId, likeId);
		return SUCCESS;
	}
	
	public String addSomePro(){
		GoodService gs = new GoodService();
		gs.addSomePro(inputGoodId, proId);
		return SUCCESS;
	}
}
